Modern databases often contain vast amounts of information. Even given the computing power and speed of modern computing hardware, queries against a large database can sometimes take several hours to perform. These queries can be computationally intensive both because of the large amount of data that must be processed and because data manipulation operations necessary applied to the data can be complex and are computationally expensive in and of themselves.
To reduce the computational tasks necessary to extract useful information from a database, a number of techniques have been developed, such as the use of materialized views and the optimization of user queries. When optimizing a user query, a query optimizer typically rewrites a query entered by a user into a form that is less computationally expensive to perform through a series of substitutions of equivalent expressions. Ideally, the final resulting query is in a form that represents the most efficient way of computing the result that the user desires.
Materialized views are commonly described as queries that are chosen by a database administrator to be precomputed from base tables because of a high likelihood that either that query, or similar queries, will be submitted to the database system. To the extent that a query can exploit prior computational work by computing part or all of a query from a materialized view, there is an efficiency gain. Any efficiency gain can have significant effects on computation time. Therefore, queries that make use of materialized views can be more efficient than those that reference base tables.
In many database systems, materialized views are only allowed to reference base tables. Stacked views, or views on views, refer to materialized views that may reference base tables and also other materialized views. As with typical materialized views, appropriate use of stacked views can provide efficiency gains and significantly reduce processing time. However, allowing stacked views creates additional complexities and in particular makes it difficult for a query optimizer to quickly and efficiently rewrite a query into a form that references stacked views. Therefore, there is a need for a system and method of optimizing queries so that benefits of using stacked views can be obtained.